<template>
  <div class="route-detail">
    <mt-header title="路线服务详情" fixed>
      <router-link to slot="left">
        <mt-button icon="back" @click.native="$router.back(-1)"></mt-button>
      </router-link>
      <mt-button icon="more" slot="right"></mt-button>
    </mt-header>
    <div class="personal-info">
      <h3>向导</h3>
      <div class="info">
        <div class="icon-swapper" @click="$router.push('/personal/' + user.id + '/read')">
          <img
            v-if="user.iconUrl == null || user.iconUrl == ''"
            src="static/img/server/usericon.png"
            height="80px"
          />
          <img v-else :src="$platIMG + user.iconUrl" height="80px" />
        </div>
        <div class="text-swapper">
          <div class="wrapper-info">
            <div class="info-text">{{user.nickName}}</div>
            <div class="info-text">当前角色：{{isGuideText}}</div>
            <div class="wrapper-detail" @click="$router.push('/personalData/'+ user.id)">
              <span slot="icon" class="iconfont">&#xe60a;</span>
              个人详细信息
              <span slot="icon" class="iconfont icon-angle-right">&#xe614;</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="route-content">
      <h3>行程内容</h3>
      <div class="content-list">
        <mt-cell class="cell" title="出发时间" :value="dataForm.startTime"></mt-cell>
        <mt-cell class="cell" title="目的地" :value="dataForm.destName"></mt-cell>
        <mt-cell class="cell" title="人数" :value="dataForm.maxNum"></mt-cell>
        <mt-cell class="cell" title="目的地介绍" :value="dataForm.destDesc"></mt-cell>
        <mt-cell class="cell" title="行程安排" :value="dataForm.travelArrange"></mt-cell>
        <mt-cell class="cell" title="集合方式" :value="dataForm.gatherWay"></mt-cell>
        <mt-cell class="cell" title="报名方式" :value="dataForm.signUpWay"></mt-cell>
        <mt-cell class="cell" title="退改方式" :value="dataForm.changeBackWay"></mt-cell>
        <mt-cell class="cell" title="注意事项" :value="dataForm.attention"></mt-cell>
        <mt-cell class="cell" title="风险提示" :value="dataForm.riskWarning"></mt-cell>
        <mt-cell class="cell" title="补充信息" :value="dataForm.note"></mt-cell>
      </div>
    </div>

    <div class="member-swapper">
      <!-- <h3>成员({{dataForm.num}}人)</h3> -->
      <h3>成员({{userList.length}}人)</h3>
      <ul class="member-ul" v-if="userList.length != 0">
        <li class="member-li" v-for="item in userList" :key="item.id">
          <div class="member">
            <div class="icon" @click="$router.push('/personal/' + item.userId + '/read')">
              <img
                v-if="item.userIcon == null || item.userIcon == ''"
                src="static/img/server/usericon.png"
                height="80px"
              />
              <img v-else :src="$platIMG + item.userIcon" height="80px" />
            </div>
            <div class="name">{{item.userName}}</div>
            <div class="operate">
              <button class="mint-button mint-button--primary mint-button--small">移除</button>
            </div>
          </div>
        </li>
      </ul>
      <div v-else class="not-find">该路线目前还没有成员</div>
    </div>

    <div class="submit-cancel">
      <div class="cancel" @click="$router.go(-1)">取消</div>
      <div class="submit" @click="addRouteUser()">我要报名</div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { Toast } from "mint-ui";
import { getDictionaryKey } from "@/libs/util.js";
export default {
  name: "routeServDetail",
  data() {
    return {
      user: {},
      dataForm: {},
      isGuideText: "",
      userList: []
    };
  },
  methods: {
    addRouteUser() {
      axios
        .post("/api/routeUser/edit", {
          routeId: this.$route.params.id,
          userId: this.$store.state.user.id,
          userName: this.$store.state.user.nickName,
          userIcon: this.$store.state.user.iconUrl
        })
        .then(res => {
          if (res.data.status == 1) {
            Toast("操作成功");
          } else {
            Toast("操作失败，请重试");
          }
        });
    }
  },
  mounted() {
    axios
      .get("/api/route/detail", {
        params: { id: this.$route.params.id }
      })
      .then(res => {
        if (res.data.status == 1) {
          this.dataForm = res.data.data;
        } else {
          console.log("fail");
        }
      });
    axios
      .get("/api/user/detail", {
        params: { id: this.$route.params.creator }
      })
      .then(res => {
        if (res.data.status == 1) {
          this.user = res.data.data;
          this.isGuideText = getDictionaryKey("key1004", this.user.isGuide);
        } else {
          console.log("fail");
        }
      });
    axios
      .get("/api/routeUser/userList", {
        params: { routeId: this.$route.params.id }
      })
      .then(res => {
        if (res.data.status == 1) {
          this.userList = res.data.data;
          console.log(res.data);
        } else {
          console.log("fail");
        }
      });
  }
};
</script>

<style lang="stylus" scoped>
@import '~@/assets/style/modifyMintUIColor.styl';

.route-detail {
  padding-top: 40px;
  padding-bottom: 55px;
  box-sizing: border-box;

  .mint-header>>>.mint-header-title {
    font-size: 0.4rem;
  }

  .personal-info {
    padding: 0.3rem;
    border-bottom: 10px solid #eee;

    h3 {
      font-weight: bolder;
      font-size: 0.36rem;
      margin-bottom: 0.3rem;
    }

    .info {
      display: flex;

      .icon-swapper {
        border-radius: 0.8rem;
        width: 1.6rem;
        height: 1.6rem;
        overflow: hidden;
        float: left;
      }

      .text-swapper {
        flex: 1;
        // background-color: green;
        margin-left: 0.2rem;

        .wrapper-info {
          margin-left: 0.2rem;

          .info-text {
            height: 0.4rem;
            line-height: 0.4rem;
          }

          .wrapper-detail {
            height: 0.6rem;
            line-height: 0.6rem;
            margin-top: 0.2rem;
            padding: 0 0.2rem;
            background-color: #eee;
            border-radius: 0.1rem;
          }
        }
      }
    }
  }

  .route-content {
    padding: 0.3rem 0.3rem;
    border-bottom: 10px solid #eee;

    h3 {
      font-weight: bolder;
      font-size: 0.36rem;
      margin-bottom: 0.3rem;
    }
  }

  .member-swapper {
    padding: 0.3rem;

    h3 {
      font-weight: bolder;
      font-size: 0.36rem;
      margin-bottom: 0.3rem;
    }

    .member {
      display: flex;
      vertical-align: center;
      height: 0.6rem;
      padding: 0.1rem 0.2rem;
      line-height: 0.6rem;

      .icon {
        width: 0.6rem;
        border-radius: 0.3rem;
        border: 1px solid #eee;
        box-sizing: border-box;
        overflow hidden;

        img {
          width: 100%;
          height: 100%;
        }
      }

      .name {
        flex: 1;
        margin-left: 0.2rem;
      }

      .operate {
        >>> .mint-button.mint-button--primary.mint-button--small {
          margin: 0 auto;
          height: 0.5rem;
          line-height: 0.5rem;
        }
      }
    }

    .not-find {
      padding: 10px 0;
      background-color: #fafafa;
      text-align: center;
      font-size: 16px;
      color: #999;
    }
  }

  .submit-cancel {
    height: 55px;
    z-index: 999;
    display: flex;
    line-height: 55px;
    text-align: center;
    position: fixed;
    width: 100%;
    bottom: 0;

    .cancel {
      flex: 1;
      background-color: #efefef;
    }

    .submit {
      flex: 1;
      background-color: $themeColor;
      color: #fff;
    }
  }
}
</style>